package com.yicun.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;// 电话号码适配器

import com.yicun.companyapplication.R;
import com.yicun.model.CompanyPhone;

import java.util.List;

 public class PhoneAdapter extends RecyclerView.Adapter<PhoneAdapter.PhoneViewHolder> {
    private List<CompanyPhone> phoneList;

    public PhoneAdapter(List<CompanyPhone> phoneList) {
        this.phoneList = phoneList;
    }

    @NonNull
    @Override
    public PhoneViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_phone, parent, false);
        return new PhoneViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull PhoneViewHolder holder, int position) {
        CompanyPhone phone = phoneList.get(position);
        holder.tvPhone.setText(phone.getPhoneNumber());

        // 设置电话类型标签
        String type = "";
        switch (phone.getPhoneType()) {
            case 1: type = "主要"; break;
            case 2: type = "备用"; break;
            default: type = "其他";
        }
        holder.tvType.setText(type);
    }

    @Override
    public int getItemCount() {
        return phoneList.size();
    }

    static class PhoneViewHolder extends RecyclerView.ViewHolder {
        TextView tvPhone, tvType;

        public PhoneViewHolder(@NonNull View itemView) {
            super(itemView);
            tvPhone = itemView.findViewById(R.id.tv_phone);
            tvType = itemView.findViewById(R.id.tv_type);
        }
    }
}

// 更新收藏状态到服务器

